﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Com.Toook.Common;
using System.Text;

public partial class Master_home : System.Web.UI.MasterPage
{
    //protected string StartTime;
    protected void Page_Load(object sender, EventArgs e)
    {
        //记录用户进入页面时间
        //StartTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        SetTypeMenu();
    }
    /// <summary>
    /// 设置分类菜单
    /// </summary>
    private void SetTypeMenu()
    {
        string url = Request.Path.ToLower();
        DataRow[] rows = null;
        string currentType = null;
        string typePath = "";
        if (url.Contains("/news/"))
        {
            typePath = "<a href=\"/news/list.aspx?type=";
            rows = PageData.SelectParamRows("parentId=10");
        }
        else if (url.Contains("/joke/"))
        {
            typePath = "<a href=\"/joke/list.aspx?type=";
            rows = PageData.SelectParamRows("parentId=50");
        }
        else if (url.Contains("/article/"))
        {
            typePath = "<a href=\"/article/list.aspx?type=";
            rows = PageData.SelectParamRows("parentId=60");
        }
        else if (url.Contains("/buy/"))
        {
            typePath = "<a href=\"/buy/list.aspx?type=";
            rows = PageData.SelectParamRows("parentId=70");
        }
        if (rows != null)
        {
            if (url.Contains("/list.aspx"))
            {
                if (!string.IsNullOrEmpty(Request.QueryString["type"]))
                {
                    currentType = Request.QueryString["type"];
                }
            }
            else if (url.Contains("/content.aspx"))
            {
                if (!string.IsNullOrEmpty(Request.QueryString["id"]) && Request.QueryString["id"].Length == 9)
                {
                    currentType = Request.QueryString["id"].Substring(0, 2);
                }
            }

            StringBuilder sb = new StringBuilder(512);
            sb.Append("<div id=\"typeMenu\">");
            foreach (DataRow row in rows)
            {
                sb.Append(typePath).Append(row["typeId"].ToString()).Append("\"");
                if (currentType == row["typeId"].ToString())
                {
                    sb.Append(" id=\"currentType\"");
                }
                sb.Append(">").Append(row["typeName"].ToString()).Append("</a>");
            }
            sb.Append("</div>");
            LiteralTypeMenu.Text = sb.ToString();
        }
    }
    /// <summary>
    /// 设置页面的标题、关键字、描述信息
    /// </summary>
    /// <param name="row"></param>
    public void SetTitleKeyDesc(DataRow row)
    {
        string page = Request["page"];
        int p;
        if(string.IsNullOrEmpty(page) || !int.TryParse(page, out p))
        {
            page = "_第1页";
        }
        else
        {
            page = "_第" + p.ToString() + "页";
        }
        Page.Title = row[PageColumn.title].ToString() + page;        
        metaDesc.Content = row[PageColumn.description].ToString();
        metaKey.Content = row[PageColumn.keyword].ToString();
    }
}
